/**
 * 
 */
package com.rocky.project.action.report;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import com.rocky.project.model.family.Archive;
import com.rocky.project.model.family.Attachment;
import com.rocky.project.model.family.Family;
import com.rocky.project.model.family.Person;

/**
 * @author chen
 * 控制台测试，来测试一些表达式错误，异常之类的
 */
public class ReportGenerator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new ReportGenerator();

	}

	private String docPath = "D:\\develop-tools\\iReport-3.0.0\\"; //jasper路径
	private String jasperFile = docPath + "archiveReport.jasper"; //主报表路径
	private String jrprintFile = docPath + "archiveReport.jrprint"; //输出文件
	//archiveReport_attachment.jasper
	private List mainList = null; //主报表List
	private JRDataSource jrdsMain = null; //数据源

	@SuppressWarnings("unchecked")
	public ReportGenerator() {
		this.mainList = getTestData();

		this.jrdsMain = new JRBeanCollectionDataSource(this.mainList);
		Map mp = new HashMap();
		mp.put("param1", "paramvalue2");
		mp.put("subreport_Path", docPath);
		try {
			JasperFillManager.fillReportToFile(jasperFile, mp, jrdsMain);
			JasperExportManager.exportReportToPdfFile(jrprintFile);
		} catch (JRException jre) {
			System.out.println("导出错误");
			jre.printStackTrace();
		}
	}
	@SuppressWarnings({ "unchecked", "deprecation" })
	/**
	 * 测试数据
	 */
	public static List getTestData() {
		List<ArchiveVO> mainlist = new ArrayList<ArchiveVO>();

		Archive archive = new Archive();

		Family family = new Family();
		family.setHouseholdername("户主姓名");
		family.setAddress("家庭住址");
		family.setFamilycode("邮政编码");
		Person person = new Person();
		person.setCardnumber("350100198202020202");
		person.setName("户主姓名");
		person.setBirthday(new Date(1982, 2, 2));
		person.setSex("2");
		person.setResidenceType("户籍类型");
		family.setHouseholder(person);
		Set persons = new HashSet();
		persons.add(new Object());
		family.setPersons(persons);
		archive.setFamily(family);
		Attachment pho = new Attachment();
		pho.setDisplayName("图纸一");
		pho.setType("2");
		pho.setRelativePath("c:\\1.jpg");
		pho.setSize(100L);
		pho.setName("图纸一");
		Set photoes = new HashSet();
		photoes.add(pho);
		archive.setPhotos(photoes);

		Attachment pic = new Attachment();
		pic.setDisplayName("照片一");
		pic.setType("1");
		pic.setRelativePath("c:\\2.jpg");
		pic.setSize(1000L);
		pic.setName("照片一");
		Set pics = new HashSet();
		pics.add(pic);

		Attachment att = new Attachment();
		att.setDisplayName("档案一");
		att.setType("3");
		att.setRelativePath("c:\\3.jpg");
		att.setSize(1000L);
		att.setName("档案一");
		Set atts = new HashSet();
		atts.add(att);
		archive.setArchivePics(atts);

		archive.setPics(pics);
		archive.setAreacard("土地证号");
		archive.setAreanum("dihao");
		archive.setAutonum("shenpibiaohao");
		archive.setUseful("usefull");

		ArchiveVO vo = new ArchiveVO();
		vo.initArchive(archive);
		//vo.setAttachments(attachments)
		mainlist.add(vo);

		return mainlist;

	}

}
